<?php

class Model_ItemResource {
	
	protected $resource_id;
	protected $item_id;
	protected $name;
	protected $extension;
	protected $content_type;
	protected $path;
	protected $type;
	
	public function __construct(array $options = null) {
		if (is_array ( $options )) {
			$this->setOptions ( $options );
		}
	}
	
	public function __set($name, $value) {
		$method = 'set' . ucfirst ( $name );
		if (('mapper' == $name) || ! method_exists ( $this, $method )) {
			throw new Exception ( 'Invalid content property' );
		}
		$this->$method ( $value );
	}
	
	public function __get($name) {
		$method = 'get' . ucfirst ( $name );
		if (('mapper' == $name) || ! method_exists ( $this, $method )) {
			throw new Exception ( 'Invalid content property' );
		}
		return $this->$method ();
	}
	
	public function setOptions(array $options) {
		$methods = get_class_methods ( $this );
		foreach ( $options as $key => $value ) {
			$method = 'set' . ucfirst ( $key );
			if (in_array ( $method, $methods )) {
				$this->$method ( $value );
			}
		}
	}
	
	public function setResource_id($value) {
		$this->resource_id = $value;
	}
	
	public function getResource_id() {
		return $this->resource_id;
	}
	
	public function setItem_id($value) {
		$this->item_id = $value;
	}
	
	public function getItem_id() {
		return $this->item_id;
	}
	
	public function setName($value) {
		$this->name = $value;
	}
	
	public function getName() {
		return $this->name;
	}
	
	public function setExtension($value) {
		$this->extension = $value;
	}
	
	public function getExtension() {
		return $this->extension;
	}
	
	public function setContent_type($value) {
		$this->content_type = $value;
	}
	
	public function getContent_type() {
		return $this->content_type;
	}
	
	public function setPath($value) {
		$this->path = $value;
	}
	
	public function getPath() {
		return $this->path;
	}
	
	public function setType($value) {
		$this->type = $value;
	}
	
	public function getType() {
		return $this->type;
	}
	
	public function getURI(){
		return content_url().'item_images/'.$this->getName();
	}
	
	public function getFilePath(){
		return content_path().'item_images'.DS.$this->getName();
	}
	
	public function toArray() {
		return get_object_vars ( $this );
	}
	public function save() {
		return Model_Mapper_ItemResource::newInstance ()->save ( $this );
	}

}